package top.xchch.tool.mockito.juejin;

import org.junit.Test;

import java.util.LinkedList;

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

/**
 * 为void方法抛异常
 */
public class VoidMethodWithExceptionsTest05 {

    @Test
    public void testVoidMethodsWithExceptions() throws Exception {

        LinkedList mockedList = mock(LinkedList.class);
        doThrow(new RuntimeException()).when(mockedList).clear();
        //下面会抛RuntimeException
        mockedList.clear();
    }

}
